// pageD/pageD.js
var app = getApp();
Page({
    
  /**
   * 页面的初始数据
   */
  data: {
    page:[],
    items:[],
    hungerD: 100,
    entertainD: 0,
    moneyD:0
  },
  
  go1() {
      wx.redirectTo({
        url: '/pageC/pageC',
      })
      this.setData({
        hunger:getApp().globalData.hunger -= 45,
        yule:getApp().globalData.yule += 5,
        money:getApp().globalData.money -= 13
      })
      /*wx.showModal({
        title: '炸酱面套餐',
        content: '您的饥饿值减少45，情绪值增加5！',
        showCancel:false,
        success (res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击确定')
          } else if (res.cancel) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击取消')
          }
        }
      })*/
    
    console.log(getApp().globalData.hunger)
  },

  go2() {
    wx.reLaunch({
      url: '/pageC/pageC',
    })
    this.setData({
      hunger:getApp().globalData.hunger -= 35,
      yule:getApp().globalData.yule += 3,
    money:getApp().globalData.money -= 15
    })
    /*wx.showModal({
        title: '炸酱面套餐',
        content: '您的饥饿值减少35，情绪值增加3！',
        showCancel:false,
        success (res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击确定')
          } else if (res.cancel) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击取消')
          }
        }
      })*/
  
  console.log(getApp().globalData.hunger)
},

go3() {
  wx.reLaunch({
    url: '/pageC/pageC',
  })
  this.setData({
    hunger:getApp().globalData.hunger -= 35,
    yule:getApp().globalData.yule += 15,
    money:getApp().globalData.money -= 25
  })
  /*wx.showModal({
        title: '炸酱面套餐',
        content: '您的饥饿值减少35，情绪值增加15！',
        showCancel:false,
        success (res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击确定')
          } else if (res.cancel) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击取消')
          }
        }
      })*/
console.log(getApp().globalData.hunger)
},

go4() {
  wx.reLaunch({
    url: '/pageC/pageC',
  })
  this.setData({
    hunger:getApp().globalData.hunger -= 30,
    yule:getApp().globalData.yule += 15,
    money:getApp().globalData.money -= 40
  })
  /*wx.showModal({
        title: '炸酱面套餐',
        content: '您的饥饿值减少30，情绪值增加15！',
        showCancel:false,
        success (res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击确定')
          } else if (res.cancel) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击取消')
          }
        }
      })*/

console.log(getApp().globalData.hunger)
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(getApp().globalData.hunger <= 0){
      hunger:getApp().globalData.hunger = 0 
    }
    if(getApp().globalData.hunger == 0){
      wx.showModal({
        title: '提示',
        content: '您已经饱了',
        success (res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击确定')
          } else if (res.cancel) {
            wx.reLaunch({
              url: '/pageC/pageC',
            })
            console.log('用户点击取消')
          }
        }
      })
    } 
    let page = getCurrentPages(),arr=[]
    this.setData({
      page:page,
      hungerD:getApp().globalData.hunger,
      entertainD:getApp().globalData.yule,
      moneyD:getApp().globalData.money
    })
    for(let i=0;i<this.data.page.length;i++){
      var temp = page[i].route.split('/')[0] 
      arr.push(temp);
    }
    this.setData({
      items:arr
    })
    console.log("D11111",Date.now())
  },

  onReady: function () {
    console.log("D22222",Date.now())

  },

  onShow: function () {
    console.log("D33333",Date.now())
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if(getApp().globalData.hunger <= 0){
      hunger:getApp().globalData.hunger = 0 
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})